<template>
<div class="app-container">
  <loading v-show="loading"></loading>
  <el-card class="box-card searchBox searchFormStyle" style="margin-bottom:1%;">
    <div slot="header" class="clearfix">
      <span>用户信息操作</span>
    </div>
    <div class="text item">
      <el-form :model="SearchDep" ref="SearchDep" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="用户账号">
              <el-input v-model="SearchDep.userAccount"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用户姓名">
              <el-input v-model="SearchDep.userName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话">
              <el-input v-model="SearchDep.phone"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item>
              <el-button type="primary" 
              icon="el-icon-plus" 
              @click="openDialog">新 增</el-button>
              <el-button type="primary" 
              icon="el-icon-search" 
              @click="getList">查 询</el-button>
              <el-button type="primary" 
              icon="el-icon-refresh" 
              @click="resetSearch">重 置</el-button>
              <el-button type="info" 
              icon="el-icon-delete" 
              @click="deleteDepar">删 除</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </el-card>
  <el-card class="box-card" style="margin-bottom:1%;">
    <div slot="header" class="clearfix">
      <span>用户信息列表</span>
    </div>
    <el-table
      :data="tableData"
      ref="tableData"
      border
      style="width: 100%;margin-bottom:1%;"
      @selection-change="handleSelectionChange"
      >
      <el-table-column
        type="selection"
        width="40">
      </el-table-column>
      <el-table-column
        label="用户账号"
        width="180"
      >
        <template slot-scope="scope">
            {{ scope.row.userAccount }}
        </template>
      </el-table-column>
      <el-table-column
        label="用户姓名"
        width="180"
       >
        <template slot-scope="scope">
            {{ scope.row.userName }}
        </template>
      </el-table-column>
      <el-table-column label="所在部门" width="180">
        <template slot-scope="scope">
          {{ scope.row.orgKey }}
        </template>
      </el-table-column>
      <el-table-column label="角色职位">
        <template slot-scope="scope">
          {{ scope.row.isPartyMember }}
        </template>
      </el-table-column>
      <el-table-column label="联系电话" width="180">
        <template slot-scope="scope">
          {{ scope.row.phone }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="300px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            icon="el-icon-document"
            @click="handleDetail(scope.$index, scope.row)">详细</el-button>
          <el-button
            size="mini"
            icon="el-icon-edit-outline"
            @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button
            size="mini"
            icon="el-icon-delete"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :paginations="paginations"></pagination>
  </el-card>
  <!--新增角色-->
  <el-dialog  :title="dialogTitle" :visible.sync="dialogFormVisible" width="80%">
    <el-form :model="addForm" :rules="rules" ref="addForm" label-width="140px">
      <el-row>
          <el-col :span="8">
            <el-form-item label="用户账号" prop="userAccount">
              <el-input v-model="addForm.userAccount" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用户姓名" prop="userName">
              <el-input v-model="addForm.userName" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="addForm.phone" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="8">
           <el-form-item label="所在部门" class="tree-input" prop="orgKey">
             <el-input type="hidden" v-model="addForm.orgKey" auto-complete="off" style="height:0;display:inline;"></el-input>
             <el-popover
                placement="bottom"
                width="400"
                :disabled="ifDisabled"
                trigger="click">
                <el-tree
                  :data="orgData"
                  show-checkbox
                  :props="defaultProps"
                  check-strictly
                  ref="orgTree"
                  node-key="orgKey"
                  :default-checked-keys="[addForm.orgKey]"
                  @check-change="handleOrgClick"
                  >
                </el-tree>
                <el-input v-model="orgName"  slot="reference" readonly></el-input>
              </el-popover>
           </el-form-item>
         </el-col>
         <el-col :span="8">
           <el-form-item label="用户角色" prop="roleId">
            <el-select v-model="roleIds" multiple collapse-tags placeholder="请选择用户角色">
              <el-option
                v-for="item in roleList"
                :key="item.roleKey"
                :label="item.roleName"
                :value="item.roleKey">
              </el-option>
            </el-select>
           </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="是否是党员">
            <el-select v-model="addForm.isPartyMember"  placeholder="请选择" style="width:100%;">
              <el-option
                v-for="item in ISNOT"
                :key="item.paramValue"
                :label="item.paramName"
                :value="item.paramValue">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button  icon="el-icon-refresh"  @click="resetForm('addForm')">重置</el-button>
      <el-button  type="primary"  icon="el-icon-plus"  @click="submitForm('addForm')">保 存</el-button>
    </div>
  </el-dialog>
  <el-dialog :title="dialogTitle" :visible.sync="detailFormVisible" width="80%">
    <el-form :model="addForm" :rules="rules" :disabled="ifDisabled" ref="addForm" label-width="140px" class="detailStyle">
      <el-row>
          <el-col :span="8">
            <span class="labelSpan">
              用户账号:
            </span>
            <span class="valueSpan">
              {{addForm.userAccount}}
            </span>
          </el-col>
          <el-col :span="8">
            <span class="labelSpan">
              用户姓名:
            </span>
            <span class="valueSpan">
              {{addForm.userName}}
            </span>
          </el-col>
          <el-col :span="8">
            <span class="labelSpan">
              联系电话:
            </span>
            <span class="valueSpan">
              {{addForm.phone}}
            </span>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="8">
           <el-form-item label="所属机构:" class="tree-input">
             <el-input type="hidden" v-model="addForm.orgKey" auto-complete="off" style="height:0;display:inline;"></el-input>
             <el-popover
                placement="bottom"
                width="400"
                disabled
               >
                <el-tree
                  :data="orgData"
                  show-checkbox
                  :props="defaultProps"
                  check-strictly
                  ref="orgTree"
                  node-key="orgKey"
                  :default-checked-keys="[addForm.orgKey]"
                  @check="handleOrgClick"
                  >
                </el-tree>
                <el-input v-model="orgName"  slot="reference" readonly></el-input>
              </el-popover>
           </el-form-item>
         </el-col>
         <el-col :span="8">
           <el-form-item label="用户角色" prop="roleId">
            <el-select v-model="roleIds" multiple placeholder="请选择用户角色">
              <el-option
                v-for="item in roleList"
                :key="item.roleKey"
                :label="item.roleName"
                :value="item.roleKey">
              </el-option>
            </el-select>
           </el-form-item>
         </el-col>
         <el-col :span="8">
           <el-form-item label="行政职务" prop="partyOrgPost">
            <el-select v-model="partyOrgPost" multiple placeholder="请选择用户角色">
              <el-option
                v-for="item in partyOrgPostList"
                :key="item.paramValue"
                :label="item.paramName"
                :value="item.paramValue">
              </el-option>
            </el-select>
           </el-form-item>
         </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="是否是党员:">
            <el-select v-model="addForm.isPartyMember"  placeholder="请选择" style="width:100%;">
              <el-option
                v-for="item in ISNOT"
                :key="item.paramValue"
                :label="item.paramName"
                :value="item.paramValue">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</div>
</template>
<script>
import Loading from '@/components/loading/loading'
import pagination from '@/components/pagination/index'
import { getUserList, userDetail, addUser, deleteUser } from '@/api/resource/user'
import { isvalidPhone, isvalidIdCard, isvalidWord, isvalidNumber, isvalidRequire } from '@/utils/validate'
import { transform } from '@/utils/trans'
// 非空
var validateRequire = (rule, value, callback) => {
  if (!isvalidRequire(value)) {
    callback(new Error('请输入必填项'))
  } else {
    callback()
  }
}
// 数字验证
var validNumber = (rule, value, callback) => {
  if (!isvalidNumber(value)) {
    callback(new Error('只能输入大于0的数字'))
  } else {
    callback()
  }
}
// 手机号
var validPhone = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入电话号码'))
  } else if (!isvalidPhone(value)) {
    callback(new Error('请输入正确的11位手机号码'))
  } else {
    callback()
  }
}
// 非空
var validRequire = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请选择所属单位'))
  } else {
    callback()
  }
}
// 身份证号
var validId = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入身份证号码'))
  } else if (!isvalidIdCard(value)) {
    callback(new Error('请输入正确的身份证号码'))
  } else {
    callback()
  }
}

// 汉字跟字母
var validWord = (rule, value, callback) => {
  if (!value) {
    callback(new Error(''))
  } else if (!isvalidWord(value)) {
    callback(new Error('只能输入汉字或字母'))
  } else {
    callback()
  }
}
export default {
  components: {
    Loading,
    pagination
  },
  data() {
    this.permissionHandle = this.$permissionHandle
    return {
      dialogTitle: '',
      loading: false,
      totalNum: 0,
      SearchDep: {
        userName: '',
        userAccount: '',
        orgKey: '',
        role: '',
        isPartyMember: '',
        partyOrgPost: '',
        phone: '',
        pageSize: '10',
        pageNum: '1'
      },
      paginations: {
        totalNum: 0,
        currentPage: 1,
        pageSize: 10
      },
      deleteDep: {
        orgKey: ''
      },
      deleteDepArry: [],
      // 是否是党员
      isPartyMember: false,
      // 是否是失联党员
      isLostMember: false,
      // 是否流动党员
      isOutGoing: false,
      // 页面所有参数
      EDUCATION: [], // 学历
      MARITALSTATUS: [], // 婚姻状况
      NATION: [], // 民族
      NEWSOCIALTYPE: [], // 新社会阶层类型
      POST: [], // 工作岗位类型
      SEX: [], // 性别
      TECHNICALPOSITION: [], // 聘任专业技术职务类型
      TYPE: [], // 人员类别
      ISNOT: [], // 是否询问
      allDepartmentData: [],
      tableData: [],
      pickerOptionsStart: {},
      pickerOptionsEnd: {},
      // 禁用表单
      ifDisabled: false,
      // 新增角色数据
      addForm: {
        userAccount: '',
        userName: '',
        phone: '',
        orgKey: '',
        isPartyMember: '002',
        partyOrgInfoKey: '',
        idNumber: '',
        sex: '',
        nation: '',
        natives: '',
        isTwNative: '',
        birthday: '',
        education: '',
        type: '',
        joinPartyDate: '',
        formalPartyDate: '',
        post: '',
        joinWorkDate: '',
        address: '',
        mobilePhone: '',
        maritalStatus: '',
        archivesMngUnit: '',
        technicalPosition: '',
        newSocialType: '',
        frontlineSituation: '',
        trainSituation: '',
        isMigrantWorker: '',
        isLostPartyMember: '002',
        isFlowPartyMember: '002',
        outgoingFlow: '',
        infoIntegrity: '',
        lostSituation: '',
        lostTime: '',
        roleId: []
      },
      orgName: '',
      partyOrgName: '',
      dialogFormVisible: false, // 新增弹出框状态
      detailFormVisible: false,
      // 列表所选数据集合
      multipleSelection: [],
      rules: {
        userAccount: [
          { required: true, message: '请输入用户账号' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 21, message: '长度在 1 到 21 个字符', trigger: 'blur' }
        ],
        userName: [
          { required: true, message: '请输入用户姓名' },
          { min: 1, max: 21, message: '长度在 1 到 21 个字符' },
          { message: '用户姓名只能输入汉字或字母', validator: validWord }
        ],
        orgKey: [
          { required: true, message: '请选择所属行政机构', trigger: 'focus', validator: validRequire }
        ],
        phone: [
          { required: true, message: '请输入联系电话' },
          { trigger: 'blur', validator: validPhone }
        ],
        partyOrgInfoKey: [
          { required: true, message: '请选择所属党组织机构', trigger: 'focus', validator: validRequire }
        ],
        idNumber: [
          { required: true, message: '请输入身份证号' },
          { trigger: 'blur', validator: validId }
        ],
        sex: [
          { required: true, message: '请选择用户性别', trigger: 'blur' }
        ],
        nation: [
          { required: true, message: '请选择民族', trigger: 'blur' }
        ],
        natives: [
          { required: true, message: '请输入籍贯' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 31, message: '长度在 1 到 31 个字', trigger: 'blur' }
        ],
        isTwNative: [
          { required: true, message: '是否是台湾户籍', trigger: 'blur' }
        ],
        birthday: [
          { required: true, message: '请选择出生年月', trigger: 'blur' }
        ],
        education: [
          { required: true, message: '请选择用户学历', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '请选择人员类别', trigger: 'blur' }
        ],
        joinPartyDate: [
          { required: true, message: '请选择加入党组织时间', trigger: 'blur' }
        ],
        formalPartyDate: [
          { required: true, message: '请选择转为正式党员日期', trigger: 'blur' }
        ],
        post: [
          { required: true, message: '请选择工作岗位', trigger: 'blur' }
        ],
        joinWorkDate: [
          { required: true, message: '请选择参加工作时间', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入家庭住址' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 43, message: '长度在 1 到 43 个字', trigger: 'blur' }
        ],
        maritalStatus: [
          { required: true, message: '请选择婚姻状况', trigger: 'blur' }
        ],
        archivesMngUnit: [
          { required: true, message: '请输入档案管理单位名称' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 43, message: '长度在 1 到 43 个字', trigger: 'blur' }
        ],
        technicalPosition: [
          { required: true, message: '请选择聘任专业技术职务', trigger: 'blur' }
        ],
        newSocialType: [
          { required: true, message: '请选择新社会阶层类型', trigger: 'blur' }
        ],
        frontlineSituation: [
          { required: true, message: '请输入一线情况' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 170, message: '长度在 1 到 170个字', trigger: 'blur' }
        ],
        trainSituation: [
          { required: true, message: '请输入党员培训情况' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 170, message: '长度在 1 到 170个字', trigger: 'blur' }
        ],
        isMigrantWorker: [
          { required: true, message: '请选择是否是农民工', trigger: 'blur' }
        ],
        isLostPartyMember: [
          { required: true, message: '请选择是否失联党员', trigger: 'blur' }
        ],
        isFlowPartyMember: [
          { required: true, message: '请选择是否流动党员', trigger: 'blur' }
        ],
        outgoingFlow: [
          { required: true, message: '请输入外出流向' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 48, message: '长度在 1 到 48个字', trigger: 'blur' }
        ],
        infoIntegrity: [
          { required: true, message: '请输入信息完整度' },
          { type: 'number', validator: validNumber }
        ],
        lostSituation: [
          { required: true, message: '请输入失联具体情形' },
          { message: '数据不能包含特殊字符', validator: validateRequire },
          { min: 1, max: 170, message: '长度在 1 到 170个字', trigger: 'blur' }
        ],
        lostTime: [
          { required: true, message: '请选择失联日期', trigger: 'blur' }
        ],
        roleId: [
          { required: true, message: '请选择角色', trigger: 'blur' }
        ]
      },
      // 组织机构
      orgData: [],
      roleList: [],
      // 党政机构
      partyOrgData: [],
      defaultProps: {
        value: 'orgKey',
        parentId: 'parOrg',
        children: 'children',
        label: 'orgName'
      },
      partyProps: {
        value: 'partyOrgKey',
        parentId: 'parPartyOrgInfoKey',
        children: 'children',
        label: 'partyOrgName'
      },
      roleIds: [],
      partyOrgPostList: [],
      partyOrgPost: [],
      sysOrgPost: [],
      sysOrgPostList: [],
      parentOrgName: '',
      searchRole: [],
      seniorSearch: false
    }
  },
  watch: {
    roleIds: function() {
      this.addForm.roleId = this.roleIds
    },
    partyOrgPost: function() {
      this.addForm.partyOrgPost = this.partyOrgPost
    },
    sysOrgPost: function() {
      this.addForm.sysOrgPost = this.sysOrgPost
    },
    addForm: {
      handler(val, oldVal) {
        if (val.isPartyMember === '001') {
          this.isPartyMember = true
        } else {
          this.isPartyMember = false
        }

        if (val.isLostPartyMember === '001') {
          this.isLostMember = true
        } else {
          this.isLostMember = false
        }
        if (val.isFlowPartyMember === '001') {
          this.isOutGoing = true
        } else {
          this.isOutGoing = false
        }
      },
      deep: true
    },
    dialogFormVisible: function() {
      if (this.dialogFormVisible === false) {
        this.partyOrgName = ''
        this.orgName = ''
        this.$refs['addForm'].resetFields()
        this.ifDisabled = false
      }
    },
    isPartyMember: function() {
    }
  },
  created() {
    this.getList()
    const component = this
    document.onkeydown = function(e) {
      e.keyCode === 13 && component.getList()
    }
  },
  updated() {
    this.getNodes()
  },
  methods: {
    changeStart() {
      this.pickerOptionsStart = Object.assign({}, this.pickerOptionsStart, {
        disabledDate: (time) => {
          return time.getTime() > new Date(this.addForm.formalPartyDate).getTime()
        }
      })
    },
    changeEnd() {
      this.pickerOptionsEnd = Object.assign({}, this.pickerOptionsEnd, {
        disabledDate: (time) => {
          return time.getTime() < new Date(this.addForm.joinPartyDate).getTime() - 86400000
        }
      })
    },
    blurSearch() {
      this.SearchDep.pageNum = 1
      this.getList()
      this.paginations.currentPage = 1
    },
    getNodes() {
      // // 默认选中组织机构
      if (this.dialogFormVisible || this.detailFormVisible) {
        if (this.$refs.orgTree && this.$refs.orgTree.getNode(this.addForm.orgKey) !== null) {
          this.orgName = this.$refs.orgTree.getNode(this.addForm.orgKey).data.orgName
        }
        if (this.$refs.partyOrgTree && this.$refs.partyOrgTree.getNode(this.addForm.partyOrgInfoKey) !== null) {
          this.partyOrgName = this.$refs.partyOrgTree.getNode(this.addForm.partyOrgInfoKey).data.partyOrgName
        }
      }
    },
    // 修改时选择父级机构
    handleClick(data, checked, node) {
      this.partyOrgName = data.partyOrgName
      this.addForm.partyOrgInfoKey = data.partyOrgKey
      if (checked) {
        this.$refs.partyOrgTree.setCheckedNodes([])
        this.$refs.partyOrgTree.setCheckedNodes([data])
        // 交叉点击节点
      } else {
        this.$refs.partyOrgTree.setCheckedNodes([])
        // 点击已经选中的节点，置空
      }
    },
    handleOrgClick(data, checked, node) {
      if (checked) {
        this.$refs.orgTree.setCheckedNodes([])
        this.$refs.orgTree.setCheckedNodes([data])
        this.orgName = data.orgName
        this.addForm.orgKey = data.orgKey
        // 交叉点击节点
      } else {
        this.$refs.orgTree.setCheckedNodes([])
        this.orgName = ''
        this.addForm.orgKey = ''
        // 点击已经选中的节点，置空
      }
    },
    // 新增打开弹出框
    openDialog() {
      this.dialogFormVisible = true
      this.dialogTitle = '用户新增'
      this.addForm = {
        userKey: ''
      }
      this.ifDisabled = false
      this.getDetail('add')
    },
    handleEdit(index, row) {
      this.addForm = {
        userKey: row.userKey
      }
      this.getDetail('edit')
      this.ifDisabled = false
      this.dialogFormVisible = true
      this.dialogTitle = '用户修改'
    },
    handleDetail(index, row) {
      this.detailFormVisible = true
      this.dialogTitle = '用户详情'
      this.addForm = {
        userKey: row.userKey
      }
      this.getDetail('detail')
    },

    // 用户列表
    getList() {
      this.loading = true
      return new Promise((resolve, reject) => {
        getUserList(this.SearchDep).then(response => {
          console.log(response.data)
          this.tableData = response.data.entity.items
          this.partyOrgPostList = response.data.partyOrgPost
          this.roleList = response.data.roleList
          this.orgData = transform(response.data.orgList, 'orgKey', 'parOrg', 'children')
          this.ISNOT = response.data.ISNOT
          this.paginations.totalNum = parseInt(response.data.entity.itemsTotalCount)
          resolve()
          this.loading = false
        }).catch(error => {
          this.loading = false
          reject(error)
        })
      })
    },

    // 用户编辑及用户新增参数等信息
    getDetail(parmater) {
      return new Promise((resolve, reject) => {
        userDetail(this.addForm).then(response => {
          this.EDUCATION = response.data.EDUCATION
          this.MARITALSTATUS = response.data.MARITALSTATUS
          this.NATION = response.data.NATION
          this.NEWSOCIALTYPE = response.data.NEWSOCIALTYPE
          this.POST = response.data.POST
          this.SEX = response.data.SEX
          this.TECHNICALPOSITION = response.data.TECHNICALPOSITION
          this.TYPE = response.data.TYPE
          this.ISNOT = response.data.ISNOT
          this.roleList = response.data.roleList
          this.partyOrgPostList = response.data.partyOrgPost
          this.sysOrgPostList = response.data.sysOrgPost
          this.roleIds = []
          this.partyOrgPost = []
          this.sysOrgPost = []
          if (response.data.entity.partyOrgPost) {
            this.partyOrgPost = JSON.parse(response.data.entity.partyOrgPost)
            this.addForm.partyOrgPost = this.partyOrgPost
          }
          if (response.data.partyMemberInfo && response.data.partyMemberInfo.sysOrgPost) {
            this.sysOrgPost = JSON.parse(response.data.partyMemberInfo.sysOrgPost)
            this.addForm.sysOrgPost = this.sysOrgPost
          }
          response.data.userRoles.forEach(element => {
            this.roleIds.push(element.roleId)
          })
          this.addForm.roleId = this.roleIds
          this.orgData = transform(response.data.orgList, 'orgKey', 'parOrg', 'children')
          this.partyOrgData = transform(response.data.partyOrgList, 'partyOrgKey', 'parPartyOrgInfoKey', 'children')
          if (parmater === 'edit' || parmater === 'detail') {
            if (response.data.partyMemberInfo) {
              this.addForm = {
                userKey: response.data.entity.userKey,
                userAccount: response.data.entity.userAccount,
                userName: response.data.entity.userName,
                phone: response.data.entity.phone,
                orgKey: response.data.entity.orgKey,
                isPartyMember: response.data.entity.isPartyMember,
                partyOrgInfoKey: response.data.partyMemberInfo.partyOrgInfoKey,
                idNumber: response.data.partyMemberInfo.idNumber,
                sex: response.data.partyMemberInfo.sex,
                nation: response.data.partyMemberInfo.nation,
                natives: response.data.partyMemberInfo.natives,
                isTwNative: response.data.partyMemberInfo.isTwNative,
                birthday: response.data.partyMemberInfo.birthday,
                education: response.data.partyMemberInfo.education,
                type: response.data.partyMemberInfo.type,
                joinPartyDate: response.data.partyMemberInfo.joinPartyDate,
                formalPartyDate: response.data.partyMemberInfo.formalPartyDate,
                post: response.data.partyMemberInfo.post,
                joinWorkDate: response.data.partyMemberInfo.joinWorkDate,
                address: response.data.partyMemberInfo.address,
                mobilePhone: response.data.partyMemberInfo.mobilePhone,
                maritalStatus: response.data.partyMemberInfo.maritalStatus,
                archivesMngUnit: response.data.partyMemberInfo.archivesMngUnit,
                technicalPosition: response.data.partyMemberInfo.technicalPosition,
                newSocialType: response.data.partyMemberInfo.newSocialType,
                frontlineSituation: response.data.partyMemberInfo.frontlineSituation,
                trainSituation: response.data.partyMemberInfo.trainSituation,
                isMigrantWorker: response.data.partyMemberInfo.isMigrantWorker,
                isLostPartyMember: response.data.partyMemberInfo.isLostPartyMember,
                isFlowPartyMember: response.data.partyMemberInfo.isFlowPartyMember,
                outgoingFlow: response.data.partyMemberInfo.outgoingFlow ? response.data.partyMemberInfo.outgoingFlow : '',
                infoIntegrity: response.data.partyMemberInfo.infoIntegrity,
                lostSituation: response.data.partyMemberInfo.lostSituation ? response.data.partyMemberInfo.lostSituation : '',
                lostTime: response.data.partyMemberInfo.lostTime,
                partyMemberInfoKey: response.data.partyMemberInfo.partyMemberInfoKey
              }
            } else {
              this.addForm = {
                userKey: response.data.entity.userKey,
                userAccount: response.data.entity.userAccount,
                userName: response.data.entity.userAccount,
                phone: response.data.entity.phone,
                orgKey: response.data.entity.orgKey,
                isPartyMember: response.data.entity.isPartyMember
              }
            }
            if (parmater === 'detail') {
              this.ifDisabled = true
              this.getNodes()
            }
            this.getNodes()
          } else {
            this.$refs['addForm'].resetFields()
            this.addForm = { isPartyMember: '002' }
          }
          this.loading = false
          resolve()
        }).catch(error => {
          this.loading = false
          reject(error)
        })
      })
    },
    addData() {
      this.loading = true
      return new Promise((resolve, reject) => {
        this.addForm.roleId = this.roleIds
        this.addForm.partyOrgPost = this.partyOrgPost
        this.addForm.sysOrgPost = this.sysOrgPost
        this.addForm.roleId = JSON.stringify(this.addForm.roleId)
        this.addForm.partyOrgPost = JSON.stringify(this.addForm.partyOrgPost)
        this.addForm.sysOrgPost = JSON.stringify(this.addForm.sysOrgPost)
        addUser(this.addForm).then(response => {
          resolve()
          this.getList()
          this.dialogFormVisible = false
          this.loading = false
          this.addForm.roleId = []
          this.addForm.partyOrgPost = []
        }).catch(error => {
          this.addForm.partyOrgPost = JSON.parse(this.addForm.partyOrgPost)
          this.addForm.roleId = JSON.parse(this.addForm.roleId)
          this.loading = false
          reject(error)
        })
      })
    },
    deleteDepar() {
      if (this.deleteDepArry.length) {
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          return new Promise((resolve, reject) => {
            deleteUser({ 'userKey': JSON.stringify(this.deleteDepArry) }).then(response => {
              resolve()
              this.loading = false
              this.getList()
              this.deleteDepArry = []
            }).catch(error => {
              this.loading = false
              this.deleteDepArry = []
              reject(error)
            })
          })
        }).catch(() => {
          this.deleteDepArry = []
          this.$refs.tableData.clearSelection()
          return
        })
      } else {
        this.$message({
          showClose: true,
          message: '请至少选择一条要删除的数据',
          type: 'warning'
        })
      }
    },

    handleDelete(index, row) {
      this.deleteDepArry = []
      this.deleteDepArry.push(row.userKey)
      this.deleteDepar()
    },
    handleSelectionChange(val) {
      this.deleteDepArry = []
      this.multipleSelection = val
      this.multipleSelection.forEach(element => {
        this.deleteDepArry.push(element.userKey)
      })
    },
    // 改变分页的时候查询数据
    handleSizeChange(val) {
      console.log(val)
      this.SearchDep.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      console.log(val)
      this.SearchDep.pageNum = val
      this.getList()
    },

    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addData()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      // this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    handleNodeClick(data) {
      this.parentOrgName = data.orgName
      this.SearchDep.orgKey = data.orgKey
    },
    resetSearch() {
      this.SearchDep.userName = ''
      this.SearchDep.userAccount = ''
      this.SearchDep.orgKey = ''
      this.SearchDep.role = ''
      this.SearchDep.isPartyMember = ''
      this.SearchDep.partyOrgPost = ''
      this.SearchDep.phone = ''
      this.parentOrgName = ''
      this.getList()
      this.getAll()
    }
  }
}
</script>
<style lang="scss" scoped>
  .el-col-8{height:60px;}
  .tree-input{
    position: relative;
    margin-bottom:0;
    .el-form-item__content{line-height: auto;}
  }
  .input-tree{
      width: 100%;
      .el-scrollbar__wrap{overflow: auto;}
    }
    .tree-select,.el-date-editor{width: 100%;}
</style>
